package com.sample.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.sample.action.form.RightForm;
import com.sample.javabean.Right;
import com.sample.util.Pager;


public class RightAction extends BaseAction {
	
	private static final long serialVersionUID = 8129775720289093533L;
	private Right right = new Right();
	private RightForm form = new RightForm();
	private String role_no;
	private String right_no;
	private Pager<Right> pageList;
	//构造函数
	public RightAction() {
		super();
	}
	
	/**
	 * 查询该用户是否能够使用该功能
	 */
	public void check(){
		try {
		    System.out.println("role_no="+role_no);
		    System.out.println("right_no="+right_no);
			right.setRole_no(role_no);
			right.setRight_no(right_no);
			right.load();
			  System.out.println("right.getIf_user()"+right.getIf_user());
			ActionContext actionContext = ActionContext.getContext();
			Map session = actionContext.getSession();
			session.put("if_user",right.getIf_user());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	/**
	 * 分页显示权限
	 * @return
	 * @throws Exception
	 */
	public String listRight()throws Exception{
		try{
			right.setRole_no(role_no);
			pageList=right.list(page, size,form);
			return "listRight";
		}catch (Exception e) {
			e.printStackTrace();
			throw new Exception("分页显示失败，Exception_Action:"+e);
		}
	}
	
	/**
	 * 开启权限
	 * @return
	 */
	public String on()throws Exception{
		try {
			right.setRole_no(role_no);
			right.setRight_no(right_no);
			right.on();
			String str = this.listRight();
			return str;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Exception("启动权限失败，Exception_Action:"+e);
		}
	}
	
	
	/**
	 * 关闭权限
	 * @return
	 */
	public String off()throws Exception{
		try {
			right.setRole_no(role_no);
			right.setRight_no(right_no);
			right.off();
			String str = this.listRight();
			return str;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Exception("关闭权限失败，Exception_Action:"+e);
		}
	}

	
	
	
	//属性访问方法
	public Right getRight() {
		return right;
	}

	public void setRight(Right right) {
		this.right = right;
	}

	public RightForm getForm() {
		return form;
	}

	public void setForm(RightForm form) {
		this.form = form;
	}

	public String getRole_no() {
		return role_no;
	}

	public void setRole_no(String role_no) {
		this.role_no = role_no;
	}

	public String getRight_no() {
		return right_no;
	}

	public void setRight_no(String right_no) {
		this.right_no = right_no;
	}

	public Pager<Right> getPageList() {
		return pageList;
	}

	public void setPageList(Pager<Right> pageList) {
		this.pageList = pageList;
	}

	
	
	
}